/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * Licensed under Simplified BSD License
 *
 *
 * @author: jin Chen 
 * @date: Dec 15, 2005$
 * @version: 1.0
 */
package edu.psu.geovista.app.hce.clustering.matrix;

import org.jfree.data.DefaultKeyedValues;
import org.jfree.util.SortOrder;

import java.util.List;

public class DialogMatrixUtils {

       
    /**
     *
     * @param matrix
     * @param obname  observation name
     * @return        a list of (observtions name & similarity values) for the given observation, in order of most similar
     */
    public static DefaultKeyedValues getSimilarity(DfDialogMatrixFloat matrix, String obname){
        float[] sims = matrix.getRowSimilarity(obname);
        List rownames = matrix.getRownames();
        DefaultKeyedValues kv=new DefaultKeyedValues();
        for (int i=0;i<sims.length ;i++){
            String  name = (String) rownames.get(i);
            kv.addValue(name,sims[i]);
        }

        //sort by value
        kv.sortByValues(SortOrder.DESCENDING );
        return kv;

    }
}
